﻿using Sustainalytics.Entities.Governance;
using System;
using System.Collections.Generic;
using Sustainalytics.Governance.BusinessLogic.PdfMetadata;
using Xunit;

namespace Sustainalytics.Governance.BusinessLogic.Tests.Intergation_Tests
{
    public class GovernancePdfProfileMetadataRepositoryTests
    {
        private readonly IGovernancePdfProfileMetadataRepository _target;

        public GovernancePdfProfileMetadataRepositoryTests()
        {
            _target = new GovernancePdfProfileMetadataRepository(GovernanceInputFileFixture.GovernanceInputFileConnectionString);
        }

        /// <summary>
        /// A <see cref="GovernancePdfProfileMetadataRepository.ReadByCompanyId(System.Guid)"/>
        /// </summary>
        [Collection("GovernanceInputFileFixtureCollection")]
        public class ReadByCompanyId_Shoud : GovernancePdfProfileMetadataRepositoryTests
        {
            public readonly GovernanceInputFileFixture _fixture;

            public ReadByCompanyId_Shoud(GovernanceInputFileFixture fixture)
            {
                _fixture = fixture;
            }

            [Fact]
            public void ReturnGovernancePdfProfileMetadataListWhenCompanyIdExist()
            {
                List<GovernancePdfProfileMetadata> result = _target.ReadByCompanyId(_fixture.CompanyId);
                Assert.NotEmpty(result);
            }

            [Fact]
            public void ReturnEmptyListWhenCompanyIdDoesNotExist()
            {
                List<GovernancePdfProfileMetadata> result = _target.ReadByCompanyId(Guid.NewGuid());
                Assert.Empty(result);
            }
        }

        /// <summary>
        /// A <see cref="GovernancePdfProfileMetadataRepository.GetFileMetadata(System.Guid)"/>
        /// </summary>
        [Collection("GovernanceInputFileFixtureCollection")]
        public class GetFileMetadataByFileId_Should : GovernancePdfProfileMetadataRepositoryTests
        {
            public readonly GovernanceInputFileFixture _fixture;

            public GetFileMetadataByFileId_Should(GovernanceInputFileFixture fixture)
            {
                _fixture = fixture;
            }

            [Fact]
            private void ReturnMetadataWhenFileIdExist()
            {
                var result = _target.GetFileMetadata(_fixture.BusinessFileId);
                Assert.NotNull(result);
            }

            [Fact]
            private void ReturnNullWhenFieldDoesNotExist()
            {
                var resutl = _target.GetFileMetadata(Guid.NewGuid());
                Assert.Null(resutl);
            }
        }

        /// <summary>
        /// A <see cref="GovernancePdfProfileMetadataRepository.GetFileMetadata(System.Guid, GovernancePdfType)"/>
        /// </summary>
        [Collection("GovernanceInputFileFixtureCollection")]
        public class GetFileMetadataByCompanyId_Should : GovernancePdfProfileMetadataRepositoryTests
        {
            public readonly GovernanceInputFileFixture _fixture;

            public GetFileMetadataByCompanyId_Should(GovernanceInputFileFixture fixture)
            {
                _fixture = fixture;
            }

            [Theory]
            [InlineData(GovernancePdfType.BusinessAndFinancialProfile)]
            [InlineData(GovernancePdfType.GovernanceDataProfile)]
            private void ReturnMetadataWhenComapnyIdAndPdfProfileExist(GovernancePdfType pdfType)
            {
                var resutl = _target.GetFileMetadata(_fixture.CompanyId, pdfType);
                Assert.NotNull(resutl);
            }

            [Theory]
            [InlineData(GovernancePdfType.BusinessAndFinancialProfile)]
            [InlineData(GovernancePdfType.GovernanceDataProfile)]
            private void ReturnNullWhenCompanyIdDoesNotExist(GovernancePdfType type)
            {
                var resutl = _target.GetFileMetadata(Guid.NewGuid(), type);
                Assert.Null(resutl);
            }
        }
    }
}
